﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GMUtilitiesDotNet.ViewModels;
using ThouShaltNotBrickLevelEditor.Code.Managers;
using ThouShaltNotBrickLevelEditor.Code.GeneralObjects;
using System.ComponentModel;
using GMUtilitiesDotNet.Helpers;
using GMUtilitiesDotNet.Commands;
using System.Windows.Input;

namespace ThouShaltNotBrickLevelEditor.ViewModels
{
    public sealed class BrickStateSelectorViewModel : ViewModelBase
    {
        #region Constants
        #endregion

        #region Properties
        #region BrickStatesTypesImages
        public static readonly PropertyChangedEventArgs BrickStatesTypesImagesEventArgs = ObservableHelper.CreateArgs<BrickStateSelectorViewModel>(x => x.BrickStatesTypesImages);

        /// <summary>
        /// BrickStatesTypesImages property.
        /// </summary>
        public BrickStatesTypesImages BrickStatesTypesImages
        {
            get { return mLevelManager.BrickStatesTypesImages; }
        }
        #endregion

        #region BrickStateSelection
        public static readonly PropertyChangedEventArgs BrickStateSelectionEventArgs = ObservableHelper.CreateArgs<BrickStateSelectorViewModel>(x => x.BrickStateSelection);

        /// <summary>
        /// BrickStateSelection property.
        /// </summary>
        public BrickStateSelection BrickStateSelection
        {
            get { return mLevelManager.BrickStateSelection; }
        }
        #endregion

        private LevelManager mLevelManager;
        #endregion

        #region Events
        #endregion

        #region Commands
        #region SelectBrickStateCommand
        private RelayCommand mSelectBrickStateCommand;
        public ICommand SelectBrickStateCommand
        {
            get
            {
                if (mSelectBrickStateCommand == null)
                {
                    mSelectBrickStateCommand = new RelayCommand(
                        param => mLevelManager.SelectBrickState((BrickStateSelection)param),
                        param => mLevelManager.CanSelectBrickState());
                }
                return mSelectBrickStateCommand;
            }
        }
        #endregion
        #endregion

        #region Constructors
        public BrickStateSelectorViewModel(LevelEditorManager pLevelEditorManager)
        {
            mLevelManager = pLevelEditorManager.LevelManager;
            mLevelManager.BrickStatesTypesImagesChanged += BrickStatesTypesImagesChangedHandler;
            mLevelManager.BrickStateSelectionChanged += BrickStateSelectionChangedHandler;
        }
        #endregion

        #region Overriden Methods
        protected override void OnDisposeManaged()
        {
            mLevelManager.BrickStatesTypesImagesChanged -= BrickStatesTypesImagesChangedHandler;
            mLevelManager.BrickStateSelectionChanged -= BrickStateSelectionChangedHandler;

            base.OnDisposeManaged();
        }
        #endregion

        #region Methods
        #endregion

        #region Event Handlers
        private void BrickStatesTypesImagesChangedHandler(object sender, EventArgs e)
        {
            RaisePropertyChangedEvent(BrickStatesTypesImagesEventArgs);
        }

        private void BrickStateSelectionChangedHandler(object sender, EventArgs e)
        {
            RaisePropertyChangedEvent(BrickStateSelectionEventArgs);
        }
        #endregion

        #region Inner Classes
        #endregion
    }
}